<template>
  <div class="editor-view">
    <div class="header">
      <div class="header-content">
        <div class="header-left">
          <div class="logo">
            <div class="logo-icon">☕</div>
            <div class="logo-text">
              <h1>我爱海鲸-代码编辑器</h1>
              <span class="logo-subtitle">专业程序员开发环境</span>
            </div>
          </div>
        </div>
        <div class="header-right">
          <div class="header-stats">
            <div class="stat-item">
              <span class="stat-label">字符数</span>
              <span class="stat-value">{{ hj_getContentLength() }}</span>
            </div>
            <div class="stat-item">
              <span class="stat-label">行数</span>
              <span class="stat-value">{{ hj_getLineCount() }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="editor-wrapper">
      <CodeEditor 
        v-model="editorContent" 
        @update:modelValue="hj_handleContentChange"
      />
    </div>
    
    <div class="footer">
      <div class="footer-content">
        <div class="footer-left">
          <span class="status-indicator"></span>
          <span>编辑器已就绪</span>
        </div>
        <div class="footer-right">
          <span>支持 Java、JSON 语法高亮和智能提示</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
import CodeEditor from '../components/code-editor.vue'

export default {
  name: 'EditorView',
  components: {
    CodeEditor
  },
  setup() {
    const editorContent = ref('')

    /**
     * 处理编辑器内容变化
     * @param {string} content - 新的内容
     */
    const hj_handleContentChange = (content) => {
      editorContent.value = content
    }

    /**
     * 获取内容长度
     * @returns {number} 内容字符数
     */
    const hj_getContentLength = () => {
      return editorContent.value.length
    }

    /**
     * 获取行数
     * @returns {number} 内容行数
     */
    const hj_getLineCount = () => {
      if (!editorContent.value) return 1
      return editorContent.value.split('\n').length
    }

    return {
      editorContent,
      hj_handleContentChange,
      hj_getContentLength,
      hj_getLineCount
    }
  }
}
</script>

<style scoped>
.editor-view {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.header-left {
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  font-size: 32px;
  background: rgba(255, 255, 255, 0.2);
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.logo-text h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.logo-subtitle {
  font-size: 14px;
  opacity: 0.8;
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
}

.header-stats {
  display: flex;
  gap: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 500;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.editor-wrapper {
  flex: 1;
  overflow: hidden;
  margin: 0;
  background: #fff;
  border-radius: 0;
}

.footer {
  background: #fff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #64748b;
  font-size: 14px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.footer-right {
  color: #64748b;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 16px;
    padding: 16px;
  }
  
  .header-stats {
    gap: 16px;
  }
  
  .logo {
    gap: 12px;
  }
  
  .logo-icon {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }
  
  .logo-text h1 {
    font-size: 20px;
  }
  
  .footer-content {
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    text-align: center;
  }
}
</style>
